﻿
String.prototype.format = function () {
    var params = [].slice.apply(arguments);
    //Array.prototype.slice.apply
    var cur = this;

    1 == params.length && "object" == typeof params[0] && (params = params[0]);

    for (var idx in params) {
        var item = params[idx];

        (cur = cur.replace(new RegExp("({)" + idx + "(})", "gm"), item));

    }

    return cur;
}

Date.prototype.format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

$.barcode=function barcode(item, value) {
    //JsBarcode(item, value, { format: "CODE39", displayValue: true });
    JsBarcode(item, value, {displayValue: true });
};

$.makeQrCode=function makeQrCode(item, value) {
    var qrcode = new QRCode(document.getElementById(item), {
        width: 60,
        height: 60
    });
    qrcode.makeCode(value);
}

$.makeQrCodeDirect = function (value) {
   return qrcode.makeCode(value);
}